package by.kniazhych.core.view.game.selector {
	
	/**
	 * ...
	 * @author Boutylin Mikhail
	 */
	
		import by.kniazhych.core.events.PeaceSelectionEvent;
		import by.kniazhych.core.view.game.peace.PeaceViewFactory;
		import by.vaukalak.core.display.array.DisplayArray;
		import flash.display.DisplayObject;
		import flash.display.Sprite;
		import flash.events.MouseEvent;
	

	
	public class SelectorItem extends Sprite{
		
		private var _peaceView:DisplayObject;
		private var _type:uint;
		
		public function SelectorItem(factory:PeaceViewFactory, type:uint) {
			super();
			_type = type;
			
			this.buttonMode = true;
			this.mouseChildren = false;
			this.addEventListener(MouseEvent.ROLL_OVER, _onRollOver);
			this.addEventListener(MouseEvent.ROLL_OUT, _onRollOut);
			this.addEventListener(MouseEvent.CLICK, _onClick);
			
			graphics.beginFill(0xffffff, 1);
			graphics.drawRect(0, 0, 50, 50);
			
			_peaceView = factory.createPeace(type);
			_peaceView.x = this.width / 2;
			_peaceView.y = this.height / 2;
			addChild(_peaceView);
		}
		
		//--------------------------------------------------------------------------
		//
		//  EVENT HANDLERS
		//
		//--------------------------------------------------------------------------
		
		private function _onClick(e:MouseEvent):void {
			dispatchEvent(new PeaceSelectionEvent(PeaceSelectionEvent.PEACE_SELECTED, _type, true));
		}
		
		private function _onRollOut(e:MouseEvent):void {
			_peaceView.scaleX = _peaceView.scaleY = 1;
		}
		
		private function _onRollOver(e:MouseEvent):void {
			_peaceView.scaleX = _peaceView.scaleY = 1.2;
		}
		
	}

}